<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>武器渲染修复测试</title>
    <style>
        body {
            margin: 0;
            padding: 20px;
            background: #000;
            color: #fff;
            font-family: Arial, sans-serif;
        }
        canvas {
            border: 1px solid #333;
            background: #111;
        }
        .info {
            margin-top: 10px;
            padding: 10px;
            background: #222;
            border-radius: 5px;
        }
        .controls {
            margin-top: 10px;
            padding: 10px;
            background: #333;
            border-radius: 5px;
        }
        button {
            margin: 5px;
            padding: 8px 16px;
            background: #4a90e2;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background: #357abd;
        }
    </style>
</head>
<body>
    <h1>武器渲染修复测试</h1>
    <canvas id="testCanvas" width="800" height="600"></canvas>
    <div class="info">
        <p>测试武器渲染修复效果</p>
        <p>应该不再出现 drawImage 错误</p>
        <p>武器应该正确显示和旋转</p>
    </div>
    <div class="controls">
        <button onclick="testWeapon('knife')">测试飞刀</button>
        <button onclick="testWeapon('fireball')">测试火球</button>
        <button onclick="testWeapon('orbital')">测试环绕弹</button>
        <button onclick="testWeapon('laser')">测试激光</button>
    </div>

    <script src="js/utils.js"></script>
    <script src="js/sprite.js"></script>
    <script src="js/sprites.js"></script>
    <script src="js/pixelArt.js"></script>
    <script src="js/weapon.js"></script>
    <script>
        // 初始化精灵管理器
        window.spriteManager = new SpriteManager();
        window.pixelArtGenerator = new PixelArtGenerator();

        // 测试武器渲染
        async function testWeaponRendering() {
            const canvas = document.getElementById('testCanvas');
            const ctx = canvas.getContext('2d');
            
            // 加载测试图像
            const imageList = [
                { key: 'weapon_knife', src: 'assets/images/weapons/飞刀.png' },
                { key: 'weapon_fireball', src: window.pixelArtGenerator.generateWeaponEffect('fireball') },
                { key: 'weapon_orbital', src: window.pixelArtGenerator.generateWeaponEffect('orbital') },
                { key: 'weapon_laser', src: window.pixelArtGenerator.generateWeaponEffect('laser') }
            ];
            
            await window.spriteManager.loadImages(imageList);
            
            // 创建精灵
            window.spriteManager.createSprite('weapon_knife', 32, 32);
            window.spriteManager.createSprite('weapon_fireball', 32, 32);
            window.spriteManager.createSprite('weapon_orbital', 32, 32);
            window.spriteManager.createSprite('weapon_laser', 32, 32);
            
            console.log('精灵创建完成，可用的精灵:', Array.from(window.spriteManager.sprites.keys()));
            
            // 渲染循环
            function render() {
                ctx.clearRect(0, 0, canvas.width, canvas.height);
                
                // 绘制网格
                ctx.strokeStyle = '#333';
                ctx.lineWidth = 1;
                for (let i = 0; i < canvas.width; i += 50) {
                    ctx.beginPath();
                    ctx.moveTo(i, 0);
                    ctx.lineTo(i, canvas.height);
                    ctx.stroke();
                }
                for (let i = 0; i < canvas.height; i += 50) {
                    ctx.beginPath();
                    ctx.moveTo(0, i);
                    ctx.lineTo(canvas.width, i);
                    ctx.stroke();
                }
                
                // 绘制说明文字
                ctx.fillStyle = '#fff';
                ctx.font = '16px Arial';
                ctx.fillText('点击按钮测试不同武器', 10, 30);
                
                requestAnimationFrame(render);
            }
            
            render();
        }
        
        // 测试特定武器
        function testWeapon(weaponType) {
            const canvas = document.getElementById('testCanvas');
            const ctx = canvas.getContext('2d');
            
            // 清空画布
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            
            // 绘制网格
            ctx.strokeStyle = '#333';
            ctx.lineWidth = 1;
            for (let i = 0; i < canvas.width; i += 50) {
                ctx.beginPath();
                ctx.moveTo(i, 0);
                ctx.lineTo(i, canvas.height);
                ctx.stroke();
            }
            for (let i = 0; i < canvas.height; i += 50) {
                ctx.beginPath();
                ctx.moveTo(0, i);
                ctx.lineTo(canvas.width, i);
                ctx.stroke();
            }
            
            // 创建测试弹丸
            const testProjectile = new Projectile(400, 300, 0, 5, 20, '#FFD700', 5000);
            testProjectile.weaponType = weaponType;
            
            // 测试环绕弹
            if (weaponType === 'orbital') {
                testProjectile.isOrbital = true;
                testProjectile.orbitalAngle = 0;
            }
            
            // 渲染弹丸
            testProjectile.render(ctx);
            
            // 绘制说明文字
            ctx.fillStyle = '#fff';
            ctx.font = '16px Arial';
            ctx.fillText(`测试武器: ${weaponType}`, 10, 30);
            ctx.fillText('如果看到武器图像且没有错误，则修复成功', 10, 50);
            
            console.log(`测试武器: ${weaponType}`);
        }
        
        // 启动测试
        testWeaponRendering().catch(console.error);
    </script>
</body>
</html> 